﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media.Media3D;
using Zove.Runtime;

namespace WPF3DTutorial.Model {
    public class TetrahedronVisualizer : AbstractModelVisualizer {

        public TetrahedronVisualizer(Window1 window)
            : base(window) {
            SolutionFactory factory = new SolutionFactory();
            this.solution = factory.CreateSolution("Tetrahedron");
        }

        public override Model3DGroup Draw() {
            Model3DGroup group;

            double length = 5;
            string e = "(x0 - {0})^2+(x1-{1})^2-{2}^2";

            EquationGroup eg = new EquationGroup(new string[] {
                string.Format(e, length, length, length),
                string.Format(e, length, length, length)
            });

            double[] r = eg.Evaluate();

            Point3D p1 = new Point3D(0, 0, 0);
            Point3D p2 = new Point3D(0, 5, 0);
            Point3D p3 = new Point3D(r[0], r[1], 0);

            string x = "(x0 - {0})^2+(x1-{1})^2-(x3-{2})^2-{3}^2";

            EquationGroup egb = new EquationGroup(new string[]{
                string.Format(x, p1.X, p1.Y, p1.Z, length),
                string.Format(x, p2.X, p2.Y, p2.Z, length),
                string.Format(x, p3.X, p3.Y, p3.Z, length)
            });
            r = egb.Evaluate();

            Point3D t = new Point3D(r[0], r[1], r[2]);

            group = new Model3DGroup();

            group.Children.Add(window.CreateTriangleModel(
                p1, p2, p3));
            group.Children.Add(window.CreateTriangleModel(
                p1, p2, t));
            group.Children.Add(window.CreateTriangleModel(
                p2, p3, t));
            group.Children.Add(window.CreateTriangleModel(
                p3, p1, t));

            return group;
        }
    }
}
